Merge branch 'master' of ssh://xp-dev.com/RRRRHHHH_Code
[RRRRHHHH_Code] / ruralHouses client / src / gui / OwnerRegistrationGUI.java
index fad1933..62395d5 100644 (file)
@@ -16,11 +16,14 @@ import javax.swing.border.EmptyBorder;
 import common.AdminInterface;
 
 import configuration.___IntNames;
-import domain.Account;
 import domain.Owner;
 
 public class OwnerRegistrationGUI extends JFrame {
 
+       /**
+        * 
+        */
+       private static final long serialVersionUID = 1L;
        private JPanel panel;
        private JTextField nameField;
        private JTextField userNameField;
@@ -38,10 +41,9 @@ public class OwnerRegistrationGUI extends JFrame {
         * Create the frame.
         */
        public OwnerRegistrationGUI() {
-               
+
                try {
-                       am = (AdminInterface) Naming
-                                       .lookup(___IntNames.AdminManager);
+                       am = (AdminInterface) Naming.lookup(___IntNames.AdminManager);
                } catch (Exception e1) {
                        System.out.println("Error accessing remote authentication: "
                                        + e1.toString());
@@ -136,22 +138,32 @@ public class OwnerRegistrationGUI extends JFrame {
 
        private void jButton_ActionPerformed(ActionEvent e) {
 
-               Owner own = new Owner(this.nameField.getText(),
-                               this.bank1Field.getText() + " " + this.bank2Field.getText()
-                                               + " " + this.bank3Field.getText() + " "
-                                               + this.bank4Field.getText(), this.emailField.getText());
-               Account acc = new Account(this.userNameField.getText(),
-                               this.passField.getText(), own);
-
-               try {
-                       if (this.am.addAccount(acc)) {
-                               this.feedback.setText("Request sended");
-                       } else {
-                               this.feedback.setText("Can't send the request");
+               if (!emailField
+                               .getText()
+                               .matches(
+                                               "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$")
+                               || !this.nameField.getText().isEmpty()||this.bank1Field.getText().length()!=4 || this.bank2Field.getText().length()!=4
+                               ||this.bank3Field.getText().length()!=2 || this.bank4Field.getText().length()!=10) {
+                       Owner own = new Owner(this.nameField.getText(),
+                                       this.bank1Field.getText() + " " + this.bank2Field.getText()
+                                                       + " " + this.bank3Field.getText() + " "
+                                                       + this.bank4Field.getText(),
+                                       this.emailField.getText());
+
+                       try {
+                               if (this.am.addAccountRequest(this.userNameField.getText(),
+                                               this.passField.getText(), own)) {
+                                       this.am.saveInstance();
+                                       this.feedback.setText("Request sended");
+                               } else {
+                                       this.feedback.setText("Can't send the request");
+                               }
+                       } catch (RemoteException e1) {
+                               // TODO Auto-generated catch block
+                               e1.printStackTrace();
                        }
-               } catch (RemoteException e1) {
-                       // TODO Auto-generated catch block
-                       e1.printStackTrace();
+               } else {
+                       this.feedback.setText("Bad formatted data");
                }
 
        }